<template>

  <div>
<!--    <el-button-->
<!--        type="primary"-->
<!--        class="handle-del mr10"-->
<!--        @click="ShowAllAdmin()"-->
<!--    >展示所有数据</el-button>-->
    <div>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: $route.path }">{{ $route.meta.title }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-table
        :data=this.tableData
        border
        size="mini"
        :row-style="{height:'0'}"
        :cell-style="{padding:'0px'}"
        :header-cell-style="{background:'lightblue',color:'#262626'}"
        style="width: 100%;margin-top: 10px">
      <el-table-column
          prop="evaluatetaskid"
          label="任务号"
          align="center"
          width="100">
      </el-table-column>
      <el-table-column
          prop="schoolname"
          label="学校名称"
          align="center"
          width="280">
      </el-table-column>

      <el-table-column
          label="评估开始时间"
          align="center"
          width="250"
      ><template v-slot="scope">{{startTime(scope.row.evaluatetaskid)}}</template>
      </el-table-column>
      <el-table-column
          label="评估结束时间"
          align="center"
          width="250"
      ><template v-slot="scope">{{endTime(scope.row.evaluatetaskid)}}</template>
      </el-table-column>
      <el-table-column
          align="center"
          label="状态"
          width="150"
      ><template v-slot="scope">{{status(scope.row.evaluatetaskid)}}</template>
      </el-table-column>
      <el-table-column
          align="center"
          width="100"
          label="操作">
            <template v-slot="scope">
          　　　　　　<el-button icon="el-icon-view" type="primary" size="small" @click="showIndex(scope.row.evaluatetaskid)">查看 </el-button>
          　</template>
<!--        <el-button-->
<!--            type="primary"-->
<!--            size="small"-->
<!--            @click="showIndex()"-->
<!--        >查看</el-button>-->
      </el-table-column>
    </el-table>


  </div>
</template>

<script>
import formDate from '@/plugins/formDate'
export default {
  methods:{
    showIndex(e){
      // 参数为评价号 evaluatetaskid
      this.$router.push({path:"EvaluateIndex123ForSchoolUser",
        query:{schoolname:this.schoolname,
          taskid:e
        }})
    },

    ShowAllAdmin(){
      const _this=this
      axios.get('http://localhost:8081/evaluatetaskarrange/search/2/'+this.$route.query.schoolname).then(function (res){
        _this.tableData=res.data
      })
    },

    ShowSearch(){
      const _this=this
      axios.get("http://localhost:8081/evaluatetaskarrange/search/"+this.value+'/'+this.search).then(function (res){
        _this.tableData=res.data
        _this.search=''
      })
    },
    AdminAdd(){
      this.$router.push("/AddEvaluateTaskArrange")
    },
    edit(row){
      console.log(row.id)
      //将当前行对象传过去
      this.$router.push({
        path:'/UpdateEvaluateTaskArrange',
        //query带参数传递
        query:{
          id:row.id
        }
      })
    },
    del(row){
      const d=confirm("确定删除吗？");
      if (d){
        axios.delete('http://localhost:8081/evaluatetaskarrange/delete/'+row.id).then(()=>{
          alert("删除成功")
          location.reload();
        })
      }

    }

  },
  data(){
    return {
      search:'',
      schoolname: '',
      options: [{
        value: '1',
        label: '任务号'
      }, {
        value: '2',
        label: '学校名称'
      }, ],
      value: '',
      total:null,
      // 评价任务安排
      tableData: null,
      // 评价任务详情
      evaluatetasks:null,
      dataList: [],
      query: {"page":0, "size":20, count:0},
      column: [
        {label: "序号", prop: "id", type: "string"},
        {label: "任务号", prop: "evaluatetaskid", type: "string"},
        {label: "学校名称", prop: "schoolname", type: "string"},

      ],
      editForm: {},
      editVisible: false,
      currentIndex: null,
    }
  },
  computed:{
    startTime(){
      return (id)=>{
        for (let i of this.evaluatetasks)
        {
          if(i.evaluatetaskid===id) return formDate.formatDateTimeForHMS(i.evaluatetaskopentime)
        }
      }
    },
    endTime(){
      return (id)=>{
        for (let j of this.evaluatetasks){
          if (j.evaluatetaskid===id) return formDate.formatDateTimeForHMS(j.evaluatetaskendtime)
        }
      }
    },
    status(){
      return (id)=>{
        const now = (new Date()).getTime()
        for (let k of this.evaluatetasks){
          if (k.evaluatetaskid===id){
            let a = new Date(k.evaluatetaskopentime).getTime()
            let b = new Date(k.evaluatetaskendtime).getTime()
            if (b<now) return '已结束';
            else if(a<now && now<b) return '进行中';
            return '未开始'
          }
        }
      }
    },
  },

  created() {
      const _this=this
      const a=localStorage.getItem("access-schooluser")
      this.schoolname = this.$route.query.schoolname
      if(a){
        axios.get('http://localhost:8081/evaluatetaskarrange/search/2/'+this.schoolname).then(function (res){
          _this.tableData=res.data
          // console.log(res.data);
        })
        axios.get('http://localhost:8081/evaluatetask/findAll').then(res=>{
          console.log('data',res.data)
          this.evaluatetasks = res.data
          for (let item of this.evaluatetasks){

            console.log(formDate.formatDateTimeForHMS(item.evaluatetaskopentime))
          }
        })
      }
      else{
        this.$alert('未登录','提示',{
          confirmButtonText:'确定'
        }).then((res)=>{
          this.$router.replace({path:'/login'})
        })
      }
  }
}
</script>
